package com.ruoyi.web.controller.caipiao;

import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import cn.hutool.core.collection.CollectionUtil;
import com.ruoyi.caipiao.domain.CaipiaoPl5MethodOne;
import com.ruoyi.caipiao.service.ICaipiaoPl5HistoryService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.caipiao.domain.CaipiaoPl5MethodThree;
import com.ruoyi.caipiao.service.ICaipiaoPl5MethodThreeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 排列5方法3预测Controller
 *
 * @author ruoyi
 * @date 2025-06-07
 */
@RestController
@RequestMapping("/caipiao/three")
public class CaipiaoPl5MethodThreeController extends BaseController {
    @Autowired
    private ICaipiaoPl5MethodThreeService caipiaoPl5MethodThreeService;
    @Autowired
    private ICaipiaoPl5HistoryService caipiaoPl5HistoryService;

    /**
     * 生成排列5号码
     *
     * @param caipiaoPl5MethodTwo
     * @return
     */
    @PreAuthorize("@ss.hasPermi('caipiao:three:list')")
    @GetMapping("/generateCode")
    public AjaxResult generateCode(CaipiaoPl5MethodThree caipiaoPl5MethodTwo) {
        ArrayList<CaipiaoPl5MethodThree> caipiaoPl5MethodThrees = new ArrayList<>();
        for (int i = 0; i < 1500; i++) {
            caipiaoPl5MethodThreeService.generateCode(caipiaoPl5MethodTwo, caipiaoPl5MethodThrees);
        }
        caipiaoPl5MethodThreeService.saveBatch(caipiaoPl5MethodThrees);
        return success();
    }

    @PreAuthorize("@ss.hasPermi('caipiao:three:list')")
    @GetMapping("/checkCode")
    public AjaxResult checkCode(CaipiaoPl5MethodThree caipiaoPl5MethodTwo) {
        List<CaipiaoPl5MethodThree> caipiaoPl5MethodThrees = caipiaoPl5MethodThreeService.checkCode(caipiaoPl5MethodTwo);
        if (CollectionUtil.isNotEmpty(caipiaoPl5MethodThrees)) {
            caipiaoPl5MethodThreeService.updateBatchById(caipiaoPl5MethodThrees);
        }
        return success();
    }

    /**
     * 查询排列5方法3预测列表
     */
    @PreAuthorize("@ss.hasPermi('caipiao:three:list')")
    @GetMapping("/list")
    public TableDataInfo list(CaipiaoPl5MethodThree caipiaoPl5MethodThree) {
        startPage();
        List<CaipiaoPl5MethodThree> list = caipiaoPl5MethodThreeService.selectCaipiaoPl5MethodThreeList(caipiaoPl5MethodThree);
        return getDataTable(list);
    }

    /**
     * 导出排列5方法3预测列表
     */
    @PreAuthorize("@ss.hasPermi('caipiao:three:export')")
    @Log(title = "排列5方法3预测", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CaipiaoPl5MethodThree caipiaoPl5MethodThree) {
        List<CaipiaoPl5MethodThree> list = caipiaoPl5MethodThreeService.selectCaipiaoPl5MethodThreeList(caipiaoPl5MethodThree);
        ExcelUtil<CaipiaoPl5MethodThree> util = new ExcelUtil<CaipiaoPl5MethodThree>(CaipiaoPl5MethodThree.class);
        util.exportExcel(response, list, "排列5方法3预测数据");
    }

    /**
     * 获取排列5方法3预测详细信息
     */
    @PreAuthorize("@ss.hasPermi('caipiao:three:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(caipiaoPl5MethodThreeService.selectCaipiaoPl5MethodThreeById(id));
    }

    /**
     * 新增排列5方法3预测
     */
    @PreAuthorize("@ss.hasPermi('caipiao:three:add')")
    @Log(title = "排列5方法3预测", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CaipiaoPl5MethodThree caipiaoPl5MethodThree) {
        return toAjax(caipiaoPl5MethodThreeService.insertCaipiaoPl5MethodThree(caipiaoPl5MethodThree));
    }

    /**
     * 修改排列5方法3预测
     */
    @PreAuthorize("@ss.hasPermi('caipiao:three:edit')")
    @Log(title = "排列5方法3预测", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CaipiaoPl5MethodThree caipiaoPl5MethodThree) {
        return toAjax(caipiaoPl5MethodThreeService.updateCaipiaoPl5MethodThree(caipiaoPl5MethodThree));
    }

    /**
     * 删除排列5方法3预测
     */
    @PreAuthorize("@ss.hasPermi('caipiao:three:remove')")
    @Log(title = "排列5方法3预测", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(caipiaoPl5MethodThreeService.deleteCaipiaoPl5MethodThreeByIds(ids));
    }
}
